﻿using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Input;
using System;

namespace WinUITest
{
    public class PointerOverTrigger : StateTriggerBase
    {
        private FrameworkElement? _targetElement;
        public FrameworkElement TargetElement
        {
            get => _targetElement ?? throw new Exception("获取目标元素失败");
            set
            {
                _targetElement = value;
                _targetElement.PointerEntered += TargetElement_PointerEntered;
                _targetElement.PointerExited += TargetElement_PointerExited;
            }
        }
        private void TargetElement_PointerEntered(object sender, PointerRoutedEventArgs e) => SetActive(true);
        private void TargetElement_PointerExited(object sender, PointerRoutedEventArgs e) => SetActive(false);
    }
}
